#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+10;
int nums[N];

int leftflag(int n,int cur)
{
	int left=1,right=n;
	while(left<right)
	{
		int mid=left+(right-left)/2;
		if(nums[mid]>=cur)
		{
			right=mid;
		}
		else
		{
			left=mid+1;
		}
	}
	if(nums[left]!=cur)
	{
		return -1;
	}
	return left;
}

int rightflag(int n,int cur)
{
	int left=1,right=n;
	while(left<right)
	{
		int mid=left+(right-left+1)/2;
		if(nums[mid]<=cur)
		{
			left=mid;
		}
		else
		{
			right=mid-1;
		}
	}
	if(nums[left]!=cur)
	{
		return -1;
	}
	return left;
}
int main()
{
	int n,k;cin>>n>>k;
	long long ret=0;
	for(int i=1;i<=n;i++) cin>>nums[i];
	sort(nums+1,nums+n+1);
	for(int i=1;i<=n;i++)
	{
		int cur=nums[i]-k;
		int left=leftflag(n,cur);
		int right=rightflag(n,cur);
		if(left==-1||right==-1) continue;
		ret+=right-left+1;
	}
	cout<<ret<<endl;
}